package com.qinge.blog.controller;

import com.github.pagehelper.PageInfo;
import com.qinge.blog.entity.BlogComment;
import com.qinge.blog.service.*;
import com.qinge.blog.utils.result.JsonResult;
import com.qinge.blog.utils.result.ResultTool;
import com.qinge.blog.vo.BaseIdReqVO;
import com.qinge.blog.vo.paging.PagingReqVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author QDW
 * @date 2022/05/13 21:07
 */
@RestController
@RequestMapping("/blog/api/comment")
public class BlogCommentController {


    @Resource
    private BlogCommentService blogCommentService;

    @PostMapping("/add")
    public JsonResult add(@RequestBody BlogComment blogComment) {
        blogCommentService.add(blogComment);

        return ResultTool.success();
    }

    @PostMapping("/remove")
    public JsonResult remove(@RequestBody BaseIdReqVO idReqVO) {
        blogCommentService.removeById(idReqVO.getId());
        return ResultTool.success();
    }

    @PostMapping("/update")
    public JsonResult update(@RequestBody BlogComment blogComment) {
        blogCommentService.update(blogComment);

        return ResultTool.success();
    }

    @PostMapping("/find")
    public JsonResult find(@RequestBody BaseIdReqVO idReqVO) {
        return ResultTool.success(blogCommentService.findById(idReqVO.getId()));
    }


    @RequestMapping("/paging")
    public JsonResult paging(@RequestBody PagingReqVO<BlogComment> pagingReqVO){

        PageInfo<BlogComment> iPage= blogCommentService.paging(pagingReqVO);

        return ResultTool.success(iPage);
    }
}

